package cn.ahaiahaixx.dp.singleton;

/**
 * 单例演示
 * 
 * @author Aiden Pearce
 *
 */
public class Demo {
  public static void main(String[] args) {
    // 私有化构造，那么不能通过new创建实现
    // Singleton s =new Singleton();
    // 只能通过通过静态方法获取对象实例
    Singleton s1 = Singleton.getInstance();
    Singleton s2 = Singleton.getInstance();
    System.out.println(s1 == s2);
    s1.add();
    s2.add();
    System.out.println(s1.getCount());
    ThreadSafeSingleton tss1 = ThreadSafeSingleton.getInstance();
    ThreadSafeSingleton tss2 = ThreadSafeSingleton.getInstance();
    System.out.println(tss1 == tss2);
    System.out.println("系统中的单例============");
    Runtime r1=Runtime.getRuntime();
    Runtime r2=Runtime.getRuntime();
    System.out.println(r1=r2);
    System.out.println("Java虚拟机分配的内存"+r1.totalMemory());
    System.out.println("Java虚拟机剩余的内存"+r1.totalMemory());
    try {
      //调用外部程序
      r1.exec("notepad").waitFor();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
